package leetcode.string;

/**
 * @Description: https://leetcode.cn/problems/valid-anagram/
 * @Author Ammar
 * @Create 2023/7/12 16:28
 */
public class _242_有效的字母异位词 {
    public boolean isAnagram(String s, String t) {
        if (s == null || t == null) return false;
        if (s.length() != t.length()) return false;

        char[] schars = s.toCharArray();
        char[] tchars = t.toCharArray();
        int[] counts = new int[26];
        for (int i = 0; i < schars.length; i++) {
            counts[schars[i] - 'a']++;
        }
        for (int i = 0; i < tchars.length; i++) {
            if (--counts[tchars[i] - 'a'] < 0) return false;
        }
        return true;
    }
}
